//
//  SystermMessageViewController.m
//  UserUse
//
//  Created by angra on 16/10/17.
//  Copyright © 2016年 CJPC. All rights reserved.
//

#import "SystermMessageViewController.h"
#import "MessageTableViewCell.h"
#import "DetailMessageViewController.h"
#import "SystemMessageModel.h"
@interface SystermMessageViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,retain)UITableView *tableView;
@property (nonatomic,retain)NSMutableArray *dataArr;
@end

static NSString *const kMessageCellIdentifier = @"MessageTableViewCell";
@implementation SystermMessageViewController
- (UITableView *)tableView
{
    if(!_tableView)
    {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenFrameW, kScreenFrameH-64) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[MessageTableViewCell class] forCellReuseIdentifier:kMessageCellIdentifier];
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"系统消息";
    [self queryMessage];
    [self.view addSubview:self.tableView];
}
-(void)queryMessage
{
    LLUserModel * user = [LLUserHandle getUserData];
    self.dataArr = [NSMutableArray array];
    [AllProjectRequest queryAllMessageByUser:user.userid success:^(id responseObject) {
        if (isSuccessRequest) {
            self.dataArr = [SystemMessageModel arrayOfModelsFromDictionaries:responseObject[@"resultObject"] error:nil];
   
        }
        [self.tableView reloadData];
    } failure:^(NSString *error) {
        
    }];
}
#pragma mark tabelView delegate dataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kScaleNum(97/2);
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kMessageCellIdentifier   forIndexPath:indexPath];
    cell.model = self.dataArr[indexPath.row];
    return cell;
    
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    DetailMessageViewController *detailVC = [[DetailMessageViewController alloc]init];
    detailVC.model = self.dataArr[indexPath.row];
    [self.navigationController pushViewController:detailVC animated:YES];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
